package abel.wlmr.model;

import abel.util.HexString;
import io.netty.buffer.ByteBuf;

public class WlmrDefaultUnit extends WlmrBaseUnit {

    private HexString rest;

    /**
     * 
     */
    public WlmrDefaultUnit() {
        super();
    }

    /**
     * @param guessedLen
     */
    public WlmrDefaultUnit(short guessedLen) {
        super(guessedLen);
    }

    @Override
    public int parseBuf(ByteBuf buf) throws WlmrException {
        setRest(new HexString(buf, getGuessedLength()));

        return getGuessedLength();
    }

    @Override
    public int getMinLength() {
        return 0;
    }

    @Override
    public ByteBuf appendBuf(ByteBuf buf) {
        buf.writeBytes(rest.getBs());

        return buf;
    }

    /* (non-Javadoc)
     * @see abel.wlmr.model.WlmrDataPart#getFinalLen()
     */
    @Override
    public short getFinalLen() {
        return (short) rest.length();
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return String.format("{rest:%s}", rest);
    }

    /**
     * @return the rest
     */
    public HexString getRest() {
        return rest;
    }

    /**
     * @param rest
     *            the rest to set
     */
    public void setRest(HexString rest) {
        this.rest = rest;
    }

}
